package com.xyc.servlet;

import com.xyc.Untils.MybatisUntils;
import com.xyc.mapper.UserMapper;
import com.xyc.pojo.User;
import org.apache.ibatis.session.SqlSession;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/myLogin")
public class MyLoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        System.out.println("myLogin...");

        String username = req.getParameter("username");
        String password = req.getParameter("password");

        System.out.println("servlet获取username:"+username);
        System.out.println("servlet获取password:"+password);

        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao.xml");
        UserMapper userMapper = ctx.getBean("userMapper", UserMapper.class);
        User user = userMapper.selectByName(username);
        System.out.println("正确的"+user);

        /*
        $("#loginSuccess").after("<div class='col-md-2' style='font-size:18px;font-weight:bold;margin-left:5px;'>\n" +
            "<a href='personal.jsp'><btn class = 'btn btn-success'>个人中心</btn>\n</div>");
        $("#loginSuccess").hide();
         */

        resp.sendRedirect("index.jsp");

    }
}
